import React, { useEffect, useState, createContext } from 'react'
import { getlist, getcolor } from '../api/data'
import Child1 from './child1'

export const ArrContext = createContext(null)
export default function App() {
    const [Arr, setArr] = useState([])
    const [color, setColor] = useState('green')
    const { Provider } = ArrContext
    useEffect(() => {
        getlist().then(res => {
            if (res) {
                setArr(res)
            }
        })
    }, [])

    const A = () => {
        getcolor(getRandomColor()).then(res => {
            if (res) {
                setColor(res)
            }
        })
    }
    function getRandomColor() {

        return '#'
            + '0123456789abcdef'[Math.floor(Math.random() * 16)]
            + '0123456789abcdef'[Math.floor(Math.random() * 16)]
            + '0123456789abcdef'[Math.floor(Math.random() * 16)]
    }
    return (
        <div>
            <div style={{ color }} >顶顶顶顶女</div>
            <button onClick={() => {
                A()
            }}>点击</button>
            <Provider value={Arr}>
                <Child1 A={A} />
            </Provider>
        </div>
    )
}
